package com.coding365.service.email.controller;

import com.coding365.service.email.util.JavaMailUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/email")
public class EmailController {


    @Value("${email.sendMail}")
    private String sendMail;
    @Value("${email.sendPerson}")
    private String sendPerson;
    @Value("${email.subject}")
    private String subject;
    @Value("${email.password}")
    private String password;


    @GetMapping("/{email}/{code}")
    public Boolean postCode(@PathVariable String email, @PathVariable String code){
        String receiveMail = email;
        String receivePerson = email;
        String content = code;
        try {
            JavaMailUtil.sendMessage(sendMail,sendPerson,receiveMail,receivePerson,subject,content,password);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
